package com.pai4j.pgc.service.community;
import com.pai4j.common.enums.CommonStatusEnum;
import com.pai4j.pgc.dao.community.ICCPathAdminDAO;
import com.pai4j.pgc.dao.community.ICCPathDAO;
import com.pai4j.pgc.entity.community.CCPathAdminEntity;
import com.pai4j.pgc.entity.community.CCPathEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 *  技术社区栏目管理员
 *
 * @author: CYM-pai
 * @date: 2025/10/27 14:16
 **/
@Service
public class CCPathAdminService {


    @Autowired
    private ICCPathAdminDAO pathAdminDAO;

    @Autowired
    private ICCPathDAO pathDAO;


    /**
     * 初始化栏目管理员
     */
    public void initPathAdmin() {
        List<CCPathEntity> pathEntities = pathDAO.findAllByStatus(CommonStatusEnum.PUBLISHED.getStatus());
        List<CCPathAdminEntity> pathAdmins = pathEntities.stream().map(p -> {
            CCPathAdminEntity pathAdminEntity = new CCPathAdminEntity();
            pathAdminEntity.setPathId(p.getId());
            pathAdminEntity.setAdmin("CU_573f344c88124348a91cb6f39ecc1e9a");
            pathAdminEntity.setDeleted(false);
            return pathAdminEntity;
        }).collect(Collectors.toList());
        pathAdminDAO.saveAll(pathAdmins);
    }

    public void create(Long pathId, String admin) {
        CCPathAdminEntity pathAdminEntity = new CCPathAdminEntity();
        pathAdminEntity.setPathId(pathId);
        pathAdminEntity.setAdmin(admin);
        pathAdminEntity.setDeleted(false);
        pathAdminDAO.save(pathAdminEntity);
    }
}
